计数器Counter类与重载运算符+ 您所在的位置:网站首页 java 符号重载 计数器Counter类与重载运算符+

计数器Counter类与重载运算符+

2023-07-10 07:24| 来源: 网络整理| 查看: 265

typedef unsigned short USHORT; #include using namespace std;

class Counter { public:     Counter();     Counter(USHORT initialValue);     ~Counter(){}     USHORT getValue()const { return value; }     void setValue(USHORT x) { value = x; }     Counter operator+(const Counter&); private:     USHORT value; };

Counter::Counter(USHORT initialValue): value(initialValue) { }

Counter::Counter() :     value(0) { }

Counter Counter::operator+(const Counter& rhs) {     return Counter(value + rhs.getValue()); }

int main() {     Counter varOne(2), varTwo(4), varThree;     varThree = varOne + varTwo;     cout



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有